/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package stuff.web;

import stuff.AccountManager;
import stuff.Account;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;


/**
 *
 * @author Николай
 */
class RegistrationValidator {

    public void validate(Account acc, AccountManager accm, Errors errors) {
        String name = acc.getUserName();
        if (!StringUtils.hasLength(name)) {
            errors.rejectValue("userName", "required", "required");
        } else if (accm.getAccount(name) != null) {
            errors.rejectValue("userName", "duplicate", "already exists");
        }
    }
}

